package com.hmall.item.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hmall.item.pojo.Item;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ItemMapper extends BaseMapper<Item> {

    @Select("select * from tb_item limit #{start},#{size}")
    List<Item> findPage(Long start, Long size);

    @Select("select count(*) from tb_item")
    Long count();

    @Insert("insert into tb_item values(null,#{item.name},#{item.price},#{item.stock},#{item.image},#{item.category}" +
            ",#{item.brand},#{item.spec},#{item.sold}," +
            "#{item.commentCount},#{item.isAD},#{item.status},#{item.createTime},#{item.updateTime})"
    )
    int addItem(@Param("item") Item item);

    @Select("select count(*) from tb_item where id = #{id}")
    int exist(Long id);

    @Update("update tb_item set status= #{sta} where id = #{id}")
    void updateStatus(Long id, Long sta);

}
